package lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MxReentrantLock {

    private Lock lock = new ReentrantLock();

    private void workSynchronized() {
        try {
            lock.lock();
            System.out.println(Thread.currentThread().getName() + " work...");
            Thread.sleep(100);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }


    public static void main(String[] args) throws Exception {
        MxReentrantLock x = new MxReentrantLock();


        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                x.workSynchronized();
            }, "Thread_" + i).start();
        }

        //Thread.sleep(3000);
    }
}
